package com.itheima.test;

public class GirlFriend {
    private String name;
    private int age;

    public GirlFriend() {
    }

    public GirlFriend(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        //判断数据是否合法
        int length = name.length();
        if(length<3||length>10){
            //非法数据，抛出异常
            throw new NameException(name+"长度异常，应为3~10");
        }else{
            this.name = name;
        }
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        //判断
        if(age<18||age>40){
            throw new AgeException(age+"大小异常，应为18~40");
        }else{
            this.age = age;
        }
    }

    public String toString() {
        return "GirlFriend{name = " + name + ", age = " + age + "}";
    }
}
